<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * Class RunGamePrize
 * @package App
 */
class RunGamePrize extends Model
{
    public $timestamps = false;
    protected $table = "run_game_prize";

    const STATUS_WAITTING = 1;
    const STATUS_SHIPPING = 2;
    const STATUS_SENDING = 3;
    const STATUS_RECEIVED = 4;

    static $StatusDisplay = [
        self::STATUS_WAITTING => '待领取',
        self::STATUS_SHIPPING => '待发货',
        self::STATUS_SENDING => '待收货',
        self::STATUS_RECEIVED => '完成',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'c_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function reward()
    {
        return $this->belongsTo(RunGameReward::class, 'reward_id', 'id');
    }


    /**
     * 发货
     * @param $runGamePrize
     * @param $request
     * @return array
     */
    static function PriceSend($runGamePrize, $request)
    {
        $runGamePrize->express_name = $request->express_name;
        $runGamePrize->express_order = $request->express_order;
        $runGamePrize->status = self::STATUS_SENDING;
        $runGamePrize->updated_at = time();
        if (!$runGamePrize->save()) {
            return ['status' => 2, 'message' => '发货失败'];
        }

        return ['status' => 1, 'message' => '发货成功'];
    }

}
